home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / startMissionGui.cs < prev   
Encoding:
Text File  |  2006-09-21  |  3.1 KB  |  100 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //----------------------------------------
  7. function StartMissionGui::onWake(%this)
  8. {
  9.     if (IsObject(SM_missionList))    /// added to stop console error - ***KCF*** 21-SEP-2006
  10.     {                                 /// added to stop console error - ***KCF*** 21-SEP-2006
  11.         SM_missionList.clear();
  12.         %i = 0;
  13.         for(%file = findFirstFile($Server::MissionFileSpec); %file !$= ""; %file = findNextFile($Server::MissionFileSpec))  
  14.           if (strStr(%file, "/CVS/") == -1)
  15.              SM_missionList.addRow(%i++, getMissionDisplayName(%file) @ "\t" @ %file );
  16.         SM_missionList.sort(0);
  17.         SM_missionList.setSelectedRow(0);
  18.         SM_missionList.scrollVisible(0);
  19.   }                                   /// added to stop console error - ***KCF*** 21-SEP-2006
  20.  
  21.    // Override the next page command...
  22.    OverlayNextPage.command = "StartMissionGui.nextPage();";
  23. }
  24.  
  25.  
  26. //----------------------------------------
  27. function StartMissionGui::nextPage(%this)
  28. {
  29.    if (StartMissionGuiCheck.getValue()) {
  30.       Canvas.setContent(LoadingGui);
  31.        LOAD_MapName.setText( "Creating Server" );
  32.        LOAD_MapDescription.setText( "<font:Arial:16>Please wait while the local server is started... this server will be open to local lan and internet connections.");
  33.       Canvas.repaint();
  34.       %this.startServer();
  35.    }
  36.    else
  37.       MainMenuGui.nextPage();
  38. }
  39.  
  40. function StartMissionGui::startServer(%this)
  41. {
  42.    createServer("MultiPlayer", "demo/data/missions/"@$Client::GameType@".mis");
  43.    %conn = new GameConnection(ServerConnection);
  44.    RootGroup.add(ServerConnection);
  45.    %conn.setConnectArgs($pref::Player::Name);
  46.    %conn.setJoinPassword($Client::Password);
  47.    %conn.connectLocal();
  48. }
  49.  
  50.  
  51. //----------------------------------------
  52. function StartMissionGuiText::onWake(%this)
  53. {
  54.    // Indicate which text is to be displayed in the ML text control...
  55.    %this.fileName = "demo/client/ui/missions/start_" @ $Client::GameType @ ".txt";
  56.    echo("FileName: " @ %this.fileName);
  57.    Parent::onWake(%this);
  58. }
  59.  
  60.  
  61. //----------------------------------------
  62. function getMissionDisplayName( %missionFile ) 
  63. {
  64.    %file = new FileObject();
  65.    
  66.    %MissionInfoObject = "";
  67.    
  68.    if ( %file.openForRead( %missionFile ) ) {
  69.         %inInfoBlock = false;
  70.         
  71.         while ( !%file.isEOF() ) {
  72.             %line = %file.readLine();
  73.             %line = trim( %line );
  74.             
  75.             if( %line $= "new ScriptObject(MissionInfo) {" )
  76.                 %inInfoBlock = true;
  77.             else if( %inInfoBlock && %line $= "};" ) {
  78.                 %inInfoBlock = false;
  79.                 %MissionInfoObject = %MissionInfoObject @ %line; 
  80.                 break;
  81.             }
  82.             
  83.             if( %inInfoBlock )
  84.                %MissionInfoObject = %MissionInfoObject @ %line @ " ";     
  85.         }
  86.         
  87.         %file.close();
  88.     }
  89.     %MissionInfoObject = "%MissionInfoObject = " @ %MissionInfoObject;
  90.     eval( %MissionInfoObject );
  91.     
  92.    %file.delete();
  93.  
  94.    if( %MissionInfoObject.name !$= "" )
  95.       return %MissionInfoObject.name;
  96.    else
  97.       return fileBase(%missionFile); 
  98. }
  99.  
  100.